﻿using System.Collections.Generic;
using System.Linq.Expressions;

namespace Is.Core
{
    internal class ParameterExpressionVisitor : ExpressionVisitor
    {
        private List<ParameterExpression> _parameters;

        public IEnumerable<ParameterExpression> GetParameters(Expression expr)
        {
            _parameters = new List<ParameterExpression>();
            Visit(expr);
            return _parameters;
        }

        protected override Expression VisitParameter(
            ParameterExpression p)
        {

            if (!_parameters.Contains(p))
                _parameters.Add(p);

            return base.VisitParameter(p);
        }
    }
}
